题解 AT5632@洛谷 |5632@Atcoder 【Sum of Two Integers】

题意:输入一个整数,求有多少个由两个不同的正整数组成的无序二元组(交换数字顺序视为同一种)加起来等于这个整数。

通过数学推理(以下的除号均表示整除运算):

如果输入的整数(设为 nn)是奇数,则输出 (n1)÷2(n-1)\div 2;否则输出 n÷21n\div 2-1,但根据整除运算也可写成 (n1)÷2(n-1)\div 2

Python:

print((int(input())-1)//2)

C++:

#include <iostream>
using namespace std;

int main()
{
	int n;
    cin>>n;
    cout<<(n-1)/2<<endl;
    return 0;
}

C:

#include <stdio.h>

int main()
{
	int n;
    scanf("%d", &n);
    printf("%d\n", (n-1)/2);
    return 0;
}

伪代码:

input n
n ← floor((n-1)/2)
print n